package com.yu.footballpromotionliveadmin.controller;


import com.yu.footballpromotionliveadmin.dto.DTO;
import com.yu.footballpromotionliveadmin.page.PageInfo;
import com.yu.footballpromotionliveadmin.pojo.EventRecords;
import com.yu.footballpromotionliveadmin.service.EventRecordsService;
import com.yu.footballpromotionliveadmin.vo.EventRecordsView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class EventRecordsController {

    @Autowired
    EventRecordsService eventRecordsService;

    @GetMapping("/eventRecords")
    public DTO<EventRecords> getAllLiveAdmin() throws Exception {

        return eventRecordsService.getAllEventRecordss();
    }

    @GetMapping("/geteventRecords/{erno}")
    public DTO<EventRecords> getLiveAdminById(@PathVariable("erno") String erno) throws Exception {

        return eventRecordsService.getEventRecordsById(erno
        );
    }


    @PostMapping("/eventRecords")
    public DTO<EventRecords> getLiveAdmin(@RequestBody EventRecordsView eventRecordsView) throws Exception {
        System.out.println(eventRecordsView);
        return eventRecordsService.addEventRecords(eventRecordsView);
    }


    @PatchMapping("/eventRecords")
    public DTO<EventRecords> updateLiveAdmin(@RequestBody EventRecordsView eventRecords) throws Exception {
        System.out.println(eventRecords);
        //return null;
        return eventRecordsService.updateEventRecords(eventRecords);
    }
    @GetMapping("/getEventRecordsByPage")
    public DTO<EventRecords> ByPage(PageInfo pageInfo) throws Exception {
        DTO<EventRecords> dto = eventRecordsService.getEventRecordssByPage(pageInfo);
        return dto;
    }

    @DeleteMapping("/eventRecords/{erno}")
    public DTO<EventRecords> deleteByKey(@PathVariable("erno") String erno) throws Exception {

        DTO<EventRecords> dto = eventRecordsService.deleteEventRecords(erno);
        System.out.println(dto);
        return dto;
    }
}
